package com.fs.console.base.vo;

import com.fs.console.base.enums.CodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @desc 返回前台页面消息实体类
 * @author ACE
 */
@Data
@AllArgsConstructor
public class JsonResponse {

	/**
	 * 消息码
	 */
	private Integer code;

	/**
	 * 信息内容
	 */
	private String msg;

	/**
	 * 成功或失败
	 */
	private Boolean flag ;
	
	/**
	 * 附加数据
	 */
	private Object data;

	public JsonResponse (Boolean flag,Integer code,Object data){
		this.flag = flag;
		this.code = code;
		this.data = data;
	}

	public JsonResponse (Boolean flag,Integer code,String msg,Object data){
		this.flag = flag;
		this.code = code;
		this.data = data;
		this.msg = msg;
	}
	public JsonResponse (Boolean flag,Integer code,String msg){
		this.flag = flag;
		this.code = code;
		this.msg = msg;
	}



	public static JsonResponse success(){
		return new JsonResponse(true, CodeEnum.EX0.getKey(), CodeEnum.EX0.getValue());
	}

	public static JsonResponse success(String msg){
		return new JsonResponse(true,CodeEnum.EX0.getKey(), msg);
	}
	
	public static JsonResponse success(Object data){
		return new JsonResponse(true,CodeEnum.EX0.getKey(), data);
	}
	
	public static JsonResponse success(Integer code,String msg){
		return new JsonResponse(true, code,msg);
	}

	public static JsonResponse error(){ return error(CodeEnum.EX400); }

	public static JsonResponse error(CodeEnum codeEnum){ return new JsonResponse(false,codeEnum.getKey(),codeEnum.getValue()); }

	public static JsonResponse error(String msg){
		return new JsonResponse(false,CodeEnum.EX400.getKey(), msg);
	}
	
	public static JsonResponse error(Object data){
		return new JsonResponse(false,CodeEnum.EX400.getKey(),CodeEnum.EX400.getValue(), data);
	}
	
}
